//
//  AXFHomeHeaderView.m
//  爱鲜蜂
//
//  Created by HH on 16/11/22.
//  Copyright © 2016年 胡浩. All rights reserved.
//

#import "AXFHomeHeaderView.h"
#import "SDCycleScrollView.h"
#import "AXFCommonModel.h"
#import "AXFDetailViewController.h"

@interface AXFHomeHeaderView ()

@property (nonatomic,strong)NSArray<NSString *> *imageNames;

@property (nonatomic,strong)NSArray<AXFCommonModel *> *modelArr;

@property (nonatomic,weak)SDCycleScrollView *cycleScrollView;

@end

@implementation AXFHomeHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    
    return self;
}

- (void)setupUI
{
//    NSArray *imageNames = @[@"123.jpg",@"456.jpg"];
    self.imageNames = @[@"",@"",@""];
    
    SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero shouldInfiniteLoop:YES imageNamesGroup:self.imageNames];
    
   [cycleScrollView setClickItemOperationBlock:^(NSInteger currentIndex) {
       
       if ([_delegate respondsToSelector:@selector(jumpToDetailsController:)]) {
           NSLog(@"%@",self.modelArr[currentIndex].ID);
           [_delegate jumpToDetailsController:self.modelArr[currentIndex]];
        
       }
       
       
   }];
    
    self.cycleScrollView = cycleScrollView;
    
    //动画模式下不能设置其他小圆点的颜色
    cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleClassic;
    
    cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
    
    cycleScrollView.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    //在动画模式下才有效果.在无动画模式下改变高度会使pageController整体变变,小圆点的位置也随之改变
    //    cycleScrollView.pageControlDotSize = CGSizeMake(80, 80);
    
    cycleScrollView.pageDotColor = [UIColor cz_colorWithHex:0xe0e0e0];
    
    cycleScrollView.currentPageDotColor = [UIColor cz_colorWithHex:0xffd600];
    
    [self addSubview:cycleScrollView];
    
    [cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
}

- (void)setCycleArr:(NSArray<NSDictionary *> *)cycleArr
{
    _cycleArr = cycleArr;
    
    NSMutableArray<NSString *> *tempArr = [NSMutableArray array];
    NSMutableArray<AXFCommonModel *> *modelArr = [NSMutableArray array];
    [cycleArr enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSDictionary *activityDict = obj[ACTIVITY];
        
        AXFCommonModel *model = [AXFCommonModel yy_modelWithDictionary:activityDict];
        
        [modelArr addObject:model];
        
        [tempArr addObject:model.img];
        
    }];
    
    self.modelArr = modelArr.copy;
    self.cycleScrollView.imageURLStringsGroup = tempArr.copy;
    
    
    
}

@end
